<template>
  <view v-if="shenheStatus != 1 || !shenheAliStatus" class="refund-list-page">
    <view class="header-tabs">
      <u-tabs
        ref="uTabs"
        :list="tabList"
        :current="current"
        active-color="#FA230A"
        item-width="33.3%"
        @change="tabsChange"
        height="44"
        inactive-color="#262626"
      ></u-tabs>
    </view>
    <view class="page-content">
      <view class="orderList">
        <orderItem
          :orderitem="orderitem"
          :orderindex="orderindex"
          @toOrder="toOrder"
          @handleConfirm="handleConfirm"
          @handleCancle="handleCancle"
          v-for="(orderitem, orderindex) in orderList"
          :key="orderindex"
          :status="current"
        ></orderItem>
      </view>
    </view>
  </view>
  <Shenhe v-else-if="shenheStatus == 1"></Shenhe>
</template>

<script>
import Shenhe from '@/components/shenhe/shenhe';
import orderItem from '../components/order-refund/order-item.vue';

export default {
  components: {
    orderItem,
    Shenhe,
  },
  data() {
    return {
      tabList: [
        {
          name: this.$t('order.salesApp'),
          status: 0,
        },
        {
          name: this.$t('order.doing'),
          status: 1,
        },
        {
          name: this.$t('person.status4'),
          status: 2,
        },
      ],
      page: 1,
      current: 0,
      orderList: [],
      // 数据是否加载完毕
      noMore: false,
    };
  },
  filters: {},
  computed: {},
  onLoad(t) {
    uni.setNavigationBarTitle({
      title: this.$t('title.orderRefundList'),
    });
  },
  onShow() {
    this.page = 1;
    this.orderList = [];
    this.noMore = false;
    this.getListData();
  },
  onReachBottom() {
    if (!this.noMore) {
      this.page++;
      this.getListData();
    }
  },
  methods: {
    // api获取列表数据
    getListData() {
      let query = {
        page: this.page,
        status: this.current,
      };
      this.$allrequest.order.refundList(query).then(res => {
        if (res.code == 0) {
          this.orderList = [...this.orderList, ...res.data.list];
          uni.stopPullDownRefresh();
          if (this.orderList.length >= res.data.row_count) {
            this.noMore = true;
          } else {
            this.noMore = false;
          }
        }
      });
    },
    // 切换tab
    tabsChange(index) {
      this.current = index;
      this.orderList = [];
      this.page = 1;
      this.noMore = false;
      this.getListData();
    },
    // 跳转至订单详情页
    toOrder(e) {
      if (this.current == 0) {
        this.$utils.toUrl(
          `/order/order-detail/order-detail?id=${e.order_id}`,
          'navigate'
        );
      } else {
        this.$utils.toUrl(
          `/order/order-refund-detail/order-refund-detail?id=${e.order_refund_id}`,
          'navigate'
        );
      }
    },
    // 订单详情组件点击确认按钮
    handleConfirm(e) {
      if (
        e.type == this.$t('order.fillExp') ||
        e.type == this.$t('order.detail')
      ) {
        this.$utils.toUrl(
          `/order/order-refund-detail/order-refund-detail?id=${e.item.order_refund_id}`,
          'navigate'
        );
      }
      if (e.type == this.$t('title.orderRefund')) {
        this.$utils.toUrl(
          `/order/order-detail/order-detail?id=${e.item.order_id}`,
          'navigate'
        );
      }
      if (e.type == this.$t('diy.contact')) {
        this.$utils.makePhoneCall(this.stores.mobile);
      }
    },
    // 订单详情组件点击取消按钮
    handleCancle(e) {
      let that = this;
      if (e.type == this.$t('order.cancleApp')) {
        if (e.item.is_user_cancel == 0) {
          uni.showModal({
            title: this.$t('order.prompt'),
            content: this.$t('order.confirmCan'),
            success: function (res) {
              if (res.confirm) {
                that.cancleRefund(e.item.order_refund_id);
              } else if (res.cancel) {
              }
            },
          });
        }
      }
      if (e.type == this.$t('order.del')) {
        let that = this;
        uni.showModal({
          title: this.$t('order.prompt'),
          content: this.$t('mdAdmin.confirmCancle'),
          success: function (res) {
            if (res.confirm) {
              that.deleteRefund(e.item.order_refund_id);
            } else if (res.cancel) {
            }
          },
        });
      }
    },
    // 取消订单
    cancleRefund(id) {
      this.$allrequest.order.cancleRefund({ order_refund_id: id }).then(res => {
        if (res.code == 0) {
          this.page = 1;
          this.orderList = [];
          this.noMore = false;
          this.getListData();
        }
      });
    },
    // 删除订单
    deleteRefund(id) {
      this.$allrequest.order.deleteRefund({ order_refund_id: id }).then(res => {
        if (res.code == 0) {
          this.page = 1;
          this.orderList = [];
          this.noMore = false;
          this.getListData();
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.refund-list-page {
  min-height: 100vh;
  padding-top: 90rpx;
  padding-bottom: 40rpx;
  background-color: #f2f2f2;
  .header-tabs {
    width: 100%;
    padding-top: 20rpx;
    height: 90rpx;
    // line-height: 90rpx;
    background: #ffffff;
    position: fixed;
    top: 0;
    z-index: 1000;
    left: 0;
  }
}
</style>
